package cn.datawin.routeserver.input.service;

import cn.datawin.constant.RocketMqConstant;
import cn.datawin.sms.cmpp2.ReportLog;
import cn.datawin.sms.cmpp2.SmsDetailLog;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import static cn.datawin.constant.RocketMqConstant.SMS_CMPP_REPORT_NOTIFY_TOPIC;

/**
 * 生产者Service
 */
@Service
@Slf4j
public class ProduceService {


	@Resource(name = "defaultMQProducer")
	public DefaultMQProducer defaultMQProducer;

	/**
	 * 发送短信状态报告
	 * @param reportLog
	 */
	public void sendReportMessage(ReportLog reportLog,String accessServerTag) {
		try {//发送消息给rocketmq
			String msgStr = JSON.toJSONString(reportLog);
			Message message = new Message(SMS_CMPP_REPORT_NOTIFY_TOPIC,accessServerTag, msgStr.getBytes());
			defaultMQProducer.send(message);
		} catch (Exception e) {
			log.error("发送短信状态报告失败",e);
		}
	}

	/**
	 * 发送短信给输出服务器
	 * @param outputTopic  输出队列
	 * @param smsDetailLog 短信内容
	 * @param outputServerTag 输出队列标签
	 */
	public void sendSubmitMessage(String outputTopic,SmsDetailLog smsDetailLog, String outputServerTag) {
		try {//发送消息给rocketmq
			String msgStr = JSON.toJSONString(smsDetailLog);
			Message message = new Message(outputTopic,outputServerTag, msgStr.getBytes());
			defaultMQProducer.send(message);
		} catch (Exception e) {
			log.error("发送短信状态报告失败",e);
		}
	}

}
